<?php

class Users_DeleteAction extends SrsUsersBaseAction
{
	public function getCredentials()
	{
		return 'users.delete';
	}
	
	public function executeRead(AgaviRequestDataHolder $rd)
	{
		$user = Doctrine_Query::create()
		        ->from('User')
			      ->where('id=?', $rd->getParameter('id'))
						->fetchOne();

		if (!$user instanceof User) return $this->forward404();

		$this->setAttribute('user', $user);

		return 'Input';
	}

	public function executeWrite(AgaviRequestDataHolder $rd)
	{
		$deleted = Doctrine_Query::create()
		           ->delete('User')
		           ->where('id=?', $rd->getParameter('id'))
						   ->execute();

		return $deleted ? 'Success' : 'Error';
	}
}